#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

#define ARR_SIZE    (11) 

static int32_t max_recursive(uint32_t *data, uint32_t size)
{
    uint32_t stride = 0;
    uint32_t i = 0;

    if(1 >= size)
    {
        return data[0];
    }

    stride = size / 2;

    for(i = 0; i < stride; i++)
    {
        if(data[i] < data[i + stride])
        {
            data[i] = data[i + stride];
        }
    }

    //如果元素个数为奇数，那么就将最后一个元素和第一个元素比较
    if(0 != (size & 0x01))
    {
        if(data[0] < data[size - 1])
        {
            data[0] = data[size - 1];
        }
    }

    return max_recursive(data, stride);
}


int main(int argc, char *argv[])
{
    uint32_t a[ARR_SIZE] = {0};
    uint32_t i = 0;
    uint32_t max = 0;

    for(i = 0; i < ARR_SIZE; i++)
    {
        a[i] = random() % 100;
        printf("%u ", a[i]);
    }
    printf("\n");

    max = max_recursive(a, ARR_SIZE);
    printf("max = %u\n", max);

    return 0;
}
